home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / gas / testsuite / lib / gas-defs.exp < prev    next >
Encoding:
Text File  |  1996-07-04  |  12.3 KB  |  486 lines

  1. # Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  2.  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # DejaGnu@cygnus.com
  17.  
  18. # This file was written by Ken Raeburn (raeburn@cygnus.com).
  19.  
  20. proc gas_version {} {
  21.     global AS
  22.     catch "exec $AS -version < /dev/null" tmp
  23.     # Should find a way to discard constant parts, keep whatever's
  24.     # left, so the version string could be almost anything at all...
  25.     regexp "version (cygnus-|)\[-0-9.a-zA-Z-\]+" $tmp version
  26.     set tmp $version
  27.     clone_output "[which $AS] $version\n"
  28.     unset tmp
  29.     unset version
  30. }
  31.  
  32. proc gas_run { prog as_opts redir } {
  33.     global AS
  34.     global ASFLAGS
  35.     global comp_output
  36.     global srcdir
  37.     global subdir
  38.     global host_triplet
  39.  
  40.     verbose "Executing $AS $ASFLAGS $as_opts $prog $redir"
  41.     catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output
  42.     set comp_output [prune_system_crud $host_triplet $comp_output]
  43. }
  44.  
  45. proc all_ones { args } {
  46.     foreach x $args { if [expr $x!=1] { return 0 } }
  47.     return 1
  48. }
  49.  
  50. proc gas_start { prog as_opts } {
  51.     global AS
  52.     global ASFLAGS
  53.     global srcdir
  54.     global subdir
  55.     global spawn_id
  56.  
  57.     verbose "Starting $AS $ASFLAGS $as_opts $prog" 2
  58.     catch {
  59.     spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog
  60.     } foo
  61.     if ![regexp {^[0-9]+} $foo] then {
  62.     perror "Can't run $subdir/$prog: $foo"
  63.     }
  64. }
  65.  
  66. proc gas_finish { } {
  67.     global spawn_id
  68.  
  69.     catch "close"
  70.     catch "wait"
  71. }
  72.  
  73. proc want_no_output { testname } {
  74.     global comp_output
  75.  
  76.     if ![string match "" $comp_output] then {
  77.     send_log "$comp_output\n"
  78.     verbose "$comp_output" 3
  79.     }
  80.     if [string match "" $comp_output] then {
  81.     pass "$testname"
  82.     return 1
  83.     } else {
  84.     fail "$testname"
  85.     return 0
  86.     }
  87. }
  88.  
  89. proc gas_test_old { file as_opts testname } {
  90.     gas_run $file $as_opts ""
  91.     return [want_no_output $testname]
  92. }
  93.  
  94. proc gas_test { file as_opts var_opts testname } {
  95.     global comp_output
  96.  
  97.     set i 0
  98.     foreach word $var_opts {
  99.     set ignore_stdout($i) [string match "*>" $word]
  100.     set opt($i) [string trim $word {>}]
  101.     incr i
  102.     }
  103.     set max [expr 1<<$i]
  104.     for {set i 0} {[expr $i<$max]} {incr i} {
  105.     set maybe_ignore_stdout ""
  106.     set extra_opts ""
  107.     for {set bit 0} {(1<<$bit)<$max} {incr bit} {
  108.         set num [expr 1<<$bit]
  109.         if [expr $i&$num] then {
  110.         set extra_opts "$extra_opts $opt($bit)"
  111.         if $ignore_stdout($bit) then {
  112.             set maybe_ignore_stdout ">/dev/null"
  113.         }
  114.         }
  115.     }
  116.     set extra_opts [string trim $extra_opts]
  117.     gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout
  118.  
  119.     # Should I be able to use a conditional expression here?
  120.     if [string match "" $extra_opts] then {
  121.         want_no_output $testname
  122.     } else {
  123.         want_no_output "$testname ($extra_opts)"
  124.     }
  125.     }
  126.     if [info exists errorInfo] then {
  127.         unset errorInfo
  128.     }
  129. }
  130.  
  131. proc gas_test_ignore_stdout { file as_opts testname } {
  132.     global comp_output
  133.  
  134.     gas_run $file $as_opts ">/dev/null"
  135.     want_no_output $testname
  136. }
  137.  
  138. proc gas_test_error { file as_opts testname } {
  139.     global comp_output
  140.  
  141.     gas_run $file $as_opts ">/dev/null"
  142.     if ![string match "" $comp_output] then {
  143.     send_log "$comp_output\n"
  144.     verbose "$comp_output" 3
  145.     }
  146.     if [string match "" $comp_output] then {
  147.     fail "$testname"
  148.     } else {
  149.     pass "$testname"
  150.     }
  151. }
  152.  
  153. proc gas_exit {} {}
  154.  
  155. proc gas_init {} {
  156.     global target_cpu
  157.     global target_cpu_family
  158.     global target_family
  159.     global target_vendor
  160.     global target_os
  161.     global stdoptlist
  162.  
  163.     case "$target_cpu" in {
  164.     "m68???"        { set target_cpu_family m68k }
  165.     "i[34]86"        { set target_cpu_family i386 }
  166.     default            { set target_cpu_family $target_cpu }
  167.     }
  168.  
  169.     set target_family "$target_cpu_family-$target_vendor-$target_os"
  170.     set stdoptlist "-a>"
  171.     # Need to return an empty string.
  172.     return
  173. }
  174.  
  175. # This proc requires two input files -- the .s file containing the
  176. # assembly source, and a .d file containing the expected output from
  177. # objdump or nm or whatever, and leading comments indicating any options
  178. # to be passed to the assembler or dump program.
  179.  
  180. proc run_dump_test { name } {
  181.     global subdir srcdir
  182.     global OBJDUMP NM AS OBJCOPY
  183.     global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS
  184.     global host_triplet
  185.  
  186.     if [string match "*/*" $name] {
  187.     set file $name
  188.     set name [file tail $name]
  189.     } else {
  190.     set file "$srcdir/$subdir/$name"
  191.     }
  192.     set opt_array [slurp_options "${file}.d"]
  193.     if { $opt_array == -1 } {
  194.     unresolved $subdir/$name
  195.     return
  196.     }
  197.     set opts(as) {}
  198.     set opts(objdump) {}
  199.     set opts(nm) {}
  200.     set opts(objcopy) {}
  201.     set opts(name) {}
  202.     set opts(PROG) {}
  203.     set opts(source) {}
  204.  
  205.     foreach i $opt_array {
  206.     set opt_name [lindex $i 0]
  207.     set opt_val [lindex $i 1]
  208.     if ![info exists opts($opt_name)] {
  209.         perror "unknown option $opt_name in file $file.d"
  210.         unresolved $subdir/$name
  211.         return
  212.     }
  213.     if [string length $opts($opt_name)] {
  214.         perror "option $opt_name multiply set in $file.d"
  215.         unresolved $subdir/$name
  216.         return
  217.     }
  218.     set opts($opt_name) $opt_val
  219.     }
  220.  
  221.     if {$opts(PROG) != ""} {
  222.     switch -- $opts(PROG) {
  223.         objdump
  224.         { set program objdump }
  225.         nm
  226.         { set program nm }
  227.         objcopy
  228.         { set program objcopy }
  229.         default
  230.         { perror "unrecognized program option $opts(PROG) in $file.d"
  231.           unresolved $subdir/$name
  232.           return }
  233.     }
  234.     } elseif {$opts(objdump) == "" && $opts(nm) != ""} {
  235.     set program nm
  236.     } elseif {$opts(objdump) != "" && $opts(nm) == ""} {
  237.     set program objdump
  238.     } elseif {$opts(objcopy) != ""} {
  239.     set program objcopy
  240.     } else {
  241.     perror "dump program unspecified in $file.d"
  242.     unresolved $subdir/$name
  243.     return
  244.     }
  245.     set progopts1 $opts($program)
  246.     eval set progopts \$[string toupper $program]FLAGS
  247.     eval set binary \$[string toupper $program]
  248.     if { $opts(name) == "" } {
  249.     set testname "$subdir/$name"
  250.     } else {
  251.     set testname $opts(name)
  252.     }
  253.  
  254.     if { $opts(source) == "" } {
  255.     set sourcefile ${file}.s
  256.     } else {
  257.     set sourcefile $srcdir/$subdir/$opts(source)
  258.     }
  259.  
  260.     send_log "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n"
  261.     catch "exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output
  262.     set comp_output [prune_system_crud $host_triplet $comp_output]
  263.  
  264.     if ![string match "" $comp_output] then {
  265.     send_log "$comp_output\n"
  266.     verbose "$comp_output" 3
  267.     fail $testname
  268.     return
  269.     }
  270.  
  271.     if { [which $binary] == 0 } {
  272.     untested $testname
  273.     return
  274.     }
  275.  
  276.     if { $progopts1 == "" } { set $progopts1 "-r" }
  277.     verbose "running $binary $progopts $progopts1" 3
  278.     if { $program == "objcopy" } {
  279.     send_log "$binary $progopts $progopts1 dump.o dump.out\n"
  280.     catch "exec $binary $progopts $progopts1 dump.o dump.out" comp_output
  281.     set comp_output [prune_system_crud $host_triplet $comp_output]
  282.     if ![string match "" $comp_output] then {
  283.         send_log "$comp_output\n"
  284.         fail $testname
  285.         return
  286.     }
  287.     } else {
  288.     send_log "$binary $progopts $progopts1 dump.o > dump.out\n"
  289.     catch "exec $binary $progopts $progopts1 dump.o > dump.out" comp_output
  290.     set comp_output [prune_system_crud $host_triplet $comp_output]
  291.     if ![string match "" $comp_output] then {
  292.         send_log "$comp_output\n"
  293.         fail $testname
  294.         return
  295.     }
  296.     }
  297.  
  298.     verbose_eval {[file_contents "dump.out"]} 3
  299.     if { [regexp_diff "dump.out" "${file}.d"] } then {
  300.     fail $testname
  301.     return
  302.     }
  303.  
  304.     pass $testname
  305. }
  306.  
  307. proc slurp_options { file } {
  308.     if [catch { set f [open $file r] } x] {
  309.     #perror "couldn't open `$file': $x"
  310.     perror "$x"
  311.     return -1
  312.     }
  313.     set opt_array {}
  314.     # whitespace expression
  315.     set ws  {[     ]*}
  316.     set nws {[^     ]*}
  317.     # whitespace is ignored anywhere except within the options list;
  318.     # option names are alphabetic only
  319.     set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
  320.     while { [gets $f line] != -1 } {
  321.     set line [string trim $line]
  322.     # Whitespace here is space-tab.
  323.     if [regexp $pat $line xxx opt_name opt_val] {
  324.         # match!
  325.         lappend opt_array [list $opt_name $opt_val]
  326.     } else {
  327.         break
  328.     }
  329.     }
  330.     close $f
  331.     return $opt_array
  332. }
  333.  
  334. proc objdump { opts } {
  335.     global OBJDUMP
  336.     global comp_output
  337.     global host_triplet
  338.  
  339.     catch "exec $OBJDUMP $opts" comp_output
  340.     set comp_output [prune_system_crud $host_triplet $comp_output]
  341.     verbose "objdump output=$comp_output\n" 3
  342. }
  343.  
  344. proc objdump_start_no_subdir { prog opts } {
  345.     global OBJDUMP
  346.     global srcdir
  347.     global spawn_id
  348.  
  349.     verbose "Starting $OBJDUMP $opts $prog" 2
  350.     catch {
  351.     spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
  352.     } foo
  353.     if ![regexp {^[0-9]+} $foo] then {
  354.     perror "Can't run $prog: $foo"
  355.     }
  356. }
  357.  
  358. proc objdump_finish { } {
  359.     global spawn_id
  360.  
  361.     catch "close"
  362.     catch "wait"
  363. }
  364.  
  365. # Default timeout is 10 seconds, loses on a slow machine.  But some
  366. # configurations of dejagnu may override it.
  367. if {$timeout<120} then { set timeout 120 }
  368.  
  369. expect_after -i {
  370.     timeout            { perror "timeout" }
  371.     "virtual memory exhausted"    { perror "virtual memory exhausted" }
  372.     buffer_full            { perror "buffer full" }
  373.     eof                { perror "eof" }
  374. }
  375.  
  376. # regexp_diff, based on simple_diff taken from ld test suite
  377. #    compares two files line-by-line
  378. #    file1 contains strings, file2 contains regexps and #-comments
  379. #    blank lines are ignored in either file
  380. #    returns non-zero if differences exist
  381. #
  382. proc regexp_diff { file_1 file_2 } {
  383.  
  384.     set eof -1
  385.     set end 0
  386.     set differences 0
  387.     set diff_pass 0
  388.  
  389.     if [file exists $file_1] then {
  390.     set file_a [open $file_1 r]
  391.     } else {
  392.     warning "$file_1 doesn't exist"
  393.     return 1
  394.     }
  395.  
  396.     if [file exists $file_2] then {
  397.     set file_b [open $file_2 r]
  398.     } else {
  399.     fail "$file_2 doesn't exist"
  400.     close $file_a
  401.     return 1
  402.     }
  403.  
  404.     verbose " Regexp-diff'ing: $file_1 $file_2" 2
  405.  
  406.     while { $differences == 0 && $end == 0 } {
  407.     set line_a ""
  408.     set line_b ""
  409.     while { [string length $line_a] == 0 } {
  410.         if { [gets $file_a line_a] == $eof } {
  411.         set end 1
  412.         break
  413.         }
  414.     }
  415.     while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
  416.         if [ string match "#pass" $line_b ] {
  417.         set end 1
  418.         set diff_pass 1
  419.         break
  420.         }
  421.         if { [gets $file_b line_b] == $eof } {
  422.         set end 1
  423.         break
  424.         }
  425.     }
  426.     if { $end } { break }
  427.     verbose "regexp \"^$line_b$\"\nline   \"$line_a\"" 3
  428.     if ![regexp "^$line_b$" "$line_a"] {
  429.         send_log "regexp_diff match failure\n"
  430.         send_log "regexp \"^$line_b$\"\nline   \"$line_a\"\n"
  431.         set differences 1
  432.     }
  433.     }
  434.  
  435.     if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
  436.     send_log "different lengths\n"
  437.     verbose "different lengths" 3
  438.     set differences 1
  439.     }
  440.  
  441.     close $file_a
  442.     close $file_b
  443.  
  444.     return $differences
  445. }
  446.  
  447. proc file_contents { filename } {
  448.     set file [open $filename r]
  449.     set contents [read $file]
  450.     close $file
  451.     return $contents
  452. }
  453.  
  454. proc verbose_eval { expr { level 1 } } {
  455.     global verbose
  456.     if $verbose>$level then { eval verbose "$expr" $level }
  457. }
  458.  
  459. # This definition is taken from an unreleased version of DejaGnu.  Once
  460. # that version gets released, and has been out in the world for a few
  461. # months at least, it may be safe to delete this copy.
  462. if ![string length [info proc prune_system_crud]] {
  463.     #
  464.     # prune_system_crud -- delete various system verbosities from TEXT on SYSTEM
  465.     #
  466.     # An example is:
  467.     # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
  468.     #
  469.     # SYSTEM is typical $target_triplet or $host_triplet.
  470.     #
  471.     # This is useful when trying to do pattern matches on program output.
  472.     # Sites with particular verbose os's may wish to override this in site.exp.
  473.     #
  474.     proc prune_system_crud { system text } {
  475.     # This is from sun4's.  Do it for all machines for now.
  476.     # The "\\1" is to try to preserve a "\n" but only if necessary.
  477.     regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
  478.  
  479.     # It might be tempting to get carried away and delete blank lines, etc.
  480.     # Just delete *exactly* what we're ask to, and that's it.
  481.     return $text
  482.     }
  483. }
  484.